# !/usr/bin/env python
# -*-coding:utf-8 -*-
# File       : get_entity_by_id.py
# Time       ：2021/12/8 16:12
# Author     ：caoxu
# version    ：python 3.9
# Description：get milvus entity by id
import sys
from milvus import Milvus

feature_engine_config = {
    "host": "10.51.3.34",
    "port": "19530",
    "collection_name": "litb_img_yolo_resnet50_ip"
}


def get_by_id(ids):
    milvus = Milvus(feature_engine_config["host"], feature_engine_config["port"])
    status, results = milvus.get_entity_by_id(collection_name=feature_engine_config["collection_name"],
                                              ids=ids)

    print('len results:', len(results))
    file_path = sys.argv[1] + '_data.txt'
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(str(results))
    file.close()


if __name__ == '__main__':
    get_by_id(ids=[int(sys.argv[1])])